#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
"""
@author:apple
@file:demo02.py
@time:2022/03/11
"""
from selenium.webdriver import Chrome
from selenium.webdriver.common import by
import time
from browsermobproxy import Server
from selenium.webdriver.chrome.options import Options

server = Server(r'./browsermob-proxy-2.1.4/bin/browsermob-proxy')
server.start()
proxy = server.create_proxy()

chrome_options = Options()

chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--proxy-server={0}'.format(proxy.proxy))

web = Chrome(options=chrome_options)
proxy.new_har("baidu", options={'captureHeaders': True, 'captureContent': True})
web.get("https://cooperation.uniontech.com/app/8ed12597-5f06-4501-ba3a-689c1da6b437/5fa4eb6bb023180e387f54be/5fa4ec7e7e29f70c868ca686")
time.sleep(2)

web.find_element(by=by.By.XPATH,value='//*[@id="txtMobilePhone"]').send_keys("lizhiqiao@uniontech.com")
time.sleep(1)
web.find_element(by=by.By.XPATH,value='//*[@id="app"]/div/div[1]/div[3]/div[2]/input').send_keys("Y4yhl9t!")

time.sleep(1)

web.find_element(by=by.By.XPATH,value='//*[@id="app"]/div/div[1]/span[1]').click()

time.sleep(3)

#
# title_element = web.find_element(by=by.By.XPATH, value='/html/body/div[1]/div/section[1]/section[1]/div/div[2]/div[3]/div/div/div/div/div[3]/div[4]/div/div[1]/span[1]')
# print(title_element.text)
# print(title_element.get_attribute("title"))


# time.sleep(2)
# contents = web.find_elements(by=by.By.XPATH, value='/html/body/div[1]/div/section[1]/section[1]/div/div[2]/div[3]/div/div/div/div/div[3]/div[4]/div/div')
#
# print(len(contents))
#
# time.sleep(1)
time.sleep(10)

result = proxy.har

for entry in result['log']['entries']:
    _url = entry['request']['url']
    # # 根据URL找到数据接口
    if "/Worksheet/GetFilterRows" in _url:
        _response = entry['response']
        _content = _response['content']['text']
        # 获取接口返回内容
        print(_content)

server.stop()
web.quit()

if __name__ == '__main__':
    pass
